package com.sx.pipeline.app.base

import android.annotation.SuppressLint
import android.content.pm.ActivityInfo
import android.content.res.Configuration
import android.content.res.Resources
import android.os.Bundle
import androidx.viewbinding.ViewBinding
import com.blankj.utilcode.util.SPUtils
import com.sx.mvvmlibs.base.BaseModel
import com.sx.mvvmlibs.base.BaseViewModel
import com.sx.mvvmlibs.base.ViewBindingBaseActivity
import com.sx.pipeline.app.config.SPKey

/**
 * @Author: YY
 * @Date: 2022/4/5
 * @Description: 二次封装 ViewBindingActivity
 */
abstract class CYViewBindingBaseActivity<V: ViewBinding, VM: BaseViewModel<out BaseModel>>
    : ViewBindingBaseActivity<V, VM>(), IStatus {

    @SuppressLint("SourceLockedOrientationActivity")
    override fun onCreate(savedInstanceState: Bundle?) {
        // 强制设置为竖屏
        requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
        super.onCreate(savedInstanceState)
        // 身份类型初始化
        initIdentity(SPUtils.getInstance().getInt(SPKey.SP_IDENTITY_TYPE, 0))
    }

    override fun initData() {

    }


    override fun onConfigurationChanged(newConfig: Configuration) {
        // 非默认值
        if (newConfig.fontScale != 1f) resources
        super.onConfigurationChanged(newConfig)
    }

    override fun getResources(): Resources {
        val res = super.getResources()
        if (res.configuration.fontScale != 1f) { //非默认值
            val newConfig = Configuration()
            newConfig.setToDefaults() //设置默认
            res.updateConfiguration(newConfig, res.displayMetrics)
        }
        return res
    }
}